package ynu.edu.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import ynu.edu.entities.BaseResponse;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    
    /**
     * 处理支付异常
     */
    @ExceptionHandler(PaymentException.class)
    public BaseResponse<Void> handlePaymentException(PaymentException e) {
        log.error("支付异常：{}", e.getMessage(), e);
        return BaseResponse.error(e.getCode(), e.getMessage());
    }
    
    /**
     * 处理其他异常
     */
    @ExceptionHandler(Exception.class)
    public BaseResponse<Void> handleException(Exception e) {
        log.error("系统异常：{}", e.getMessage(), e);
        return BaseResponse.error("系统繁忙，请稍后再试");
    }
} 